package com.sam.jifenbao.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.sam.jifenbao.R;

public class RedeemDialog extends Dialog{
    private TextView redeemCostTV,confirmBtn,cancelBtn, redeemMessageTV;
    private Context context;
    private int redeemCost;
    private String redeemName;

    public RedeemDialog(Context context,int redeemCost,String redeemName) {
        super(context,android.R.style.Theme_Dialog);  // 创建对话框，并且应用Theme_Dialog这个主题设置对话框的一些属性
        this.context = context;
        this.redeemCost = redeemCost;
        this.redeemName = redeemName;
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);   // 让对话框没有标题栏，即去掉标题栏
        setContentView(R.layout.dialog_redeem_points);
        // 把对话框的背景设置为透明的，那么我们设置什么layout上去，就显示什么样，不会有额外的背景
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        findView();
        initView();
    }

    private void findView(){
        redeemCostTV = (TextView) findViewById(R.id.redeem_cost);
        confirmBtn = (TextView) findViewById(R.id.confirm_btn);
        cancelBtn = (TextView) findViewById(R.id.cancel_btn);
        redeemMessageTV = (TextView) findViewById(R.id.redeem_message);
    }

    private void initView(){
        confirmBtn.setOnClickListener(onClickListener);
        cancelBtn.setOnClickListener(onClickListener);
        redeemCostTV.setText(redeemCost+"");
        redeemMessageTV.setText(context.getString(R.string.redeem_message)+redeemName+"?");
    }

    private View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.confirm_btn:
                    dismiss(); //  关闭对话框的方法
                    if(onRedeemSccueededLinstener != null) onRedeemSccueededLinstener.onRedeemSeccueeded();
                    break;
                case R.id.cancel_btn:
                    Toast.makeText(context,"取消兑换",Toast.LENGTH_SHORT).show();
                    dismiss(); //  关闭对话框的方法
                    break;
            }
        }
    };

    private OnRedeemSccueededLinstener onRedeemSccueededLinstener;

    public void setOnRedeemSccueededLinstener(OnRedeemSccueededLinstener onRedeemSccueededLinstener) {
        this.onRedeemSccueededLinstener = onRedeemSccueededLinstener;
    }
    public interface OnRedeemSccueededLinstener {
        void onRedeemSeccueeded();
    }

}
